Single use download script - Modification [on hold]

Posted by Iulius on Pro Webmasters See other posts from Pro Webmasters or by Iulius
Published on 2013-10-16T21:36:49Z Indexed on 2013/10/17 16:25 UTC
Read the original article Hit count: 279

Filed under:
|

I have this Single use download script!

This contain 3 php files: page.php , generate.php and variables.php.

Page.php Code:

<?php

    include("variables.php");

    $key = trim($_SERVER['QUERY_STRING']);

    $keys = file('keys/keys');
    $match = false;

    foreach($keys as &$one) {
        if(rtrim($one)==$key) {
            $match = true;
            $one = '';
        }
    }

    file_put_contents('keys/keys',$keys);

    if($match !== false) {

        $contenttype = CONTENT_TYPE;
        $filename = SUGGESTED_FILENAME;
        readfile(PROTECTED_DOWNLOAD);

        exit;

    } else {


?>

<html>
    <head>
        <meta http-equiv="refresh" content="1; url=http://docs.google.com/">
        <title>Loading, please wait ...</title>
    </head>
    <body>
        Loading, please wait ...
    </body>
</html>

<?php
    }
?>

Generate.php Code:

<?php

    include("variables.php");

    $password = trim($_SERVER['QUERY_STRING']);

    if($password == ADMIN_PASSWORD) {
        $new = uniqid('key',TRUE);

        if(!is_dir('keys')) {
            mkdir('keys');
            $file = fopen('keys/.htaccess','w');
            fwrite($file,"Order allow,deny\nDeny from all");
            fclose($file);
        }

        $file = fopen('keys/keys','a');
        fwrite($file,"{$new}\n");
        fclose($file);
?>

<html>
    <head>
        <title>Page created</title>
        <style>
            nl { 
                font-family: monospace 
            }
        </style>
    </head>
    <body>
        <h1>Page key created</h1>
        Your new single-use page link:<br>
        <nl>
        <?php 
            echo "http://" . $_SERVER['HTTP_HOST'] . DOWNLOAD_PATH . "?" . $new; 
        ?></nl>
    </body>
</html>

<?php
    } else {

        header("HTTP/1.0 404 Not Found");
    }
?>

And the last one Variables.php Code:

<?

    define('PROTECTED_DOWNLOAD','download.php');

    define('DOWNLOAD_PATH','/.work/page.php');

    define('SUGGESTED_FILENAME','download-doc.php');

    define('ADMIN_PASSWORD','1234');

    define('EXPIRATION_DATE', '+36 hours');

    header("Cache-Control: no-cache, must-revalidate");
    header("Expires: ".date('U', strtotime(EXPIRATION_DATE)));

?>

The http://www.site.com/generate.php?1234 will generate a unique link like page.php?key1234567890. This link page.php?key1234567890 will be sent by email to my user.

Now how can I generate a link like this page.php?key1234567890&[email protected] ? So I think I must access the generator page like this generate.php?1234&[email protected] .

P.S. This variable will be posted on the download page by "Hello, "

I tried everthing to complete this, and no luck.

Thanks in advance for help.

© Pro Webmasters or respective owner

Related posts about php

Related posts about script